<template>
	<view class="set_content">
		<!-- 头部 -->
		<view class="content_header">
			<view class="header_info flex" @tap="toBash">
				<view class="header_left flex">
					<image :src="userInfo.headPortrait || '/static/img/user/missing-face.png' "></image>
					<view class="">{{userInfo.nickname || '您还没有设置昵称'}}</view>
				</view>
				<text class="iconfont icon-you iconStyle"></text>
			</view>
			<view class="header_address flex" @tap="navTo('/pages_Me/address/address')">
				<text class="address_title">地址管理</text>
				<text class="iconfont icon-you iconStyle"></text>
			</view>
		</view>
		<!-- 内容 -->
		<view class="content_middle">
			<view class="middle_list flex" v-for="item in middle_list" :key="item.title" @tap="navTo(item.pages)">
				<text class="middle_list_title">{{item.title}}</text>
				<text class="iconfont icon-you iconStyle"></text>
			</view>
		</view>
		
		<!-- 脚部按钮 -->
		<view class="content_footer">
			<view class="footer_change" @tap="changeAccount">切换账号</view>
			<view class="footer_out" @tap="show = true">退出登录</view>
		</view>
		
		<!-- 询问框 -->
		<u-modal :show="show" @confirm="confirm" ref="uModal" :asyncClose="true" :showCancelButton="true" title="是否确认退出登录" @cancel="show = false" confirmColor="#FD2C4C"></u-modal>
	</view>
</template>

<script>
	import { mapState, mapMutations} from 'vuex';
	import {logout} from '@/common/http/api.js'
	export default {
		data() {
			return {
				middle_list:[
					{
						title: '账户与安全',
						pages: 'pages_Me/bash/security'
					},
					{
						title: '支付设置',
						pages: ''
					},
					{
						title: '隐私设置',
						pages: ''
					},
					{
						title: '消息通知设置',
						pages: ''
					},
					{
						title: '通用',
						pages: ''
					},
				],
				show:false
			}
		},
		onLoad(){
			console.log(this.userInfo,'xxxxxxxxxxxxxxxxxx')
			if(!uni.getStorageSync("userInfo").account){
				this.$ut.msg("请先登录!")
				setTimeout(()=>{
					uni.$u.route({
						url: '/pages_Me/login/login',
						type: 'redirectTo'
					})
				},500)
				
			}
		},
		computed:{
			userInfo(){
				return uni.getStorageSync("userInfo") ? uni.getStorageSync("userInfo") : {}
			}
		},
		methods: {
			...mapMutations(['logout']),
			navTo(url){
				uni.$u.route({url})
			},
			 // 切换账号
			 changeAccount(){
				 uni.$u.route({url: 'pages_Me/login/login'})
			 },
			 // 退出登录
			 confirm() {
			 	logout().then(res=>{
			 		this.logout();
					this.show = false;
			 		this.$ut.msg("退出成功")
			 		setTimeout(() => {
			 		    uni.$u.route({
			 			    url: 'pages/index/index',
							type: 'redirectTo'
			 		    })
			 		}, 1200)
			 	}) 
			},
			// 去个人中心
			toBash(){
				uni.$u.route({url:"pages_Me/bash/bash"})
			}
		}
		
	}
</script>

<style scoped lang="scss">
	.set_content{
		width: 100vw;
		min-height: 100vh;
		
		.content_header{
			background-color: #fff;
			padding: 0 34rpx;
			.header_info{
				border-bottom: 2rpx solid #F6F6F6;
				padding: 20rpx 0;
				.header_left{
					width: 80%;
					justify-content: flex-start;
					image{
						width: 94rpx;
						height: 94rpx;
						margin-right: 43rpx;
						// border-radius: 50%;
					}
					view{
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 600;
						font-size: 26rpx;
						color: #666666;
					}
				}
			}
			.header_address{
				padding: 30rpx 0;
				
				.address_title{
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 500;
					font-size: 28rpx;
					color: #313131;
				}
			}
		}
		
		.content_middle{
			background-color: #fff;
			padding: 0 34rpx;
			margin-top: 22rpx;
			
			.middle_list{
				border-bottom: 2rpx solid #F6F6F6;
				padding: 30rpx 0;
				
				.middle_list_title{
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 500;
					font-size: 28rpx;
					color: #313131;
				}
			}
			// .middle_list:nth-last-child(){
			// 	border-bottom: none;
			// }
		}
		
		.content_footer{
			margin-top: 477rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.footer_change{
				width: 85%;
				height: 67rpx;
				text-align: center;
				line-height: 67rpx;
				color: #fff;
				background: #FD2C4C;
				border-radius: 11rpx;
				font-size: 29rpx;
				margin-bottom: 64rpx;
				border: 2rpx solid #FD2C4C;
			}
			.footer_out{
				width: 85%;
				height: 67rpx;
				color: #FD2C4C;
				text-align: center;
				line-height: 67rpx;
				background: transparent;
				border-radius: 11rpx;
				font-size: 29rpx;
				border: 2rpx solid #FD2C4C;
			}
		}
	}
	.iconStyle{
		font-size:31rpx;
		font-weight: 400;
	}
</style>
